//
//  Poker.c
//  algorithmDemo
//
//  Created by 李文深 on 16/7/11.
//  Copyright © 2016年 30pay. All rights reserved.
//  魔术师发牌问题

#include "Poker.h"
#include <stdlib.h>
#include <stdio.h>

List initEmptyList() {
    
    List head = (List)malloc(sizeof(struct Node));
    List p = head;
    for (int i=1; i <=13; i++) {
        List node = (List)malloc(sizeof(struct Node));
        node->data = 0;
        node->next = NULL;
        p->next = node;
        p = p->next;
    }
    
    p->next = head->next;
    
    free(head);
    
    return p->next;
}


void printPokerOrders(List l) {
    
    
    l->data = 1;
    List p = l;
    int countNumber = 2;
    
    while (1) {
        for (int j = 0; j < countNumber; j++) {
            p = p->next;
            if (p->data != 0) {
                j--;
            }
        }
        
        p->data = countNumber;
        countNumber ++;
        if (countNumber == 14) {
            break;
        }
        
    }
    
    p = l;
    
    do {
        printf("%d\n",p->data);
        p = p->next;
    }while (p != l);
    
}